package com.ruoyi.project.cms.notice.service.impl;

import com.ruoyi.common.exception.BusinessException;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.project.cms.notice.domain.Type;
import com.ruoyi.project.cms.notice.mapper.TypeMapper;
import com.ruoyi.project.cms.notice.service.TypeService;
import com.ruoyi.project.system.user.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TypeServiceImpl  implements TypeService {


    @Autowired
    private TypeMapper  typeMapper;

    @Override
    public List<Type> findMore(Type type) {

        return typeMapper.selectMore(type);
    }

    @Override
    public int save(Type type) {
        return typeMapper.insert(type);
    }

    @Override
    public String findTypeName(String typeName) {

        Type type = new Type();
        type.setTypeName(typeName);
        type = typeMapper.selectType(type);
        if (type != null){
            return "1";
        }
        return "0";
    }

    @Override
    public Type findTypeById(Integer typeId) {
        Type type = new Type();
        type.setTypeId(typeId);
        return typeMapper.selectType(type);
    }

    @Override
    public String findType(Type type) {
        Type t = new Type();
        if (typeMapper.selectType(type) != null){
            return "0";
        }
        t.setTypeName(type.getTypeName());
        t = typeMapper.selectType(t);
        return t == null?"0":"1";
    }

    @Override
    public int updateType(Type type) {

        return typeMapper.update(type);
    }

    @Override
    public int removeType(String ids) throws BusinessException
    {
        Integer i = 0;
        Long[] typeIds = Convert.toLongArray(ids);
        for (Long typeId : typeIds)
        {
            i = i + typeMapper.delete(typeId);
        }
        return i;
    }

    @Override
    public List<Type> typeList() {
        return typeMapper.selectAllList();
    }
}
